package com.itheima.LockTest;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Semaphore;

/**
 * @PackageName: com.itheima.LockTest
 * @ClassName: CyclicBarrierTest
 * @Author: Renyz
 * @Date: 2021/11/12 15:33
 * @Description: //TODO
 */


public class CyclicBarrierTest {


    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(5,()->{
            System.out.println("出发");
        });
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                try {
                    System.out.println("先来");
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }

            }).start();
        }

    }

}
